package cn.wolfcode.luowowo.website.controller;

import cn.wolfcode.luowowo.article.domain.StrategyCommend;
import cn.wolfcode.luowowo.article.domain.TravelCommend;
import cn.wolfcode.luowowo.article.service.IStrategyCommendService;
import cn.wolfcode.luowowo.article.service.ITravelCommendService;
import cn.wolfcode.luowowo.article.service.ITravelService;
import cn.wolfcode.luowowo.common.query.TravelQueryObject;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class IndexController {
    @Reference
    private ITravelCommendService travelCommendService;
    @Reference
    private IStrategyCommendService strategyCommendService;
    @Reference
    private ITravelService travelService;





    @RequestMapping("")
    public String index(Model model){
        //游记推荐
        List<TravelCommend> tcs = travelCommendService.selectCommendsTop5();
        model.addAttribute("tcs",tcs);
        //攻略推荐
        List<StrategyCommend> scs = strategyCommendService.selectCommendsTop5();
        model.addAttribute("scs",scs.subList(0,1));

        return "index/index";
    }



   /*
    @RequestMapping("/userInfo")
    @ResponseBody
    public Object userInfo(HttpServletRequest request, @UserParam UserInfo userInfo){
        System.out.println(userInfo);
        return userInfo;
    }*/
   //热门游记推荐
    @RequestMapping("/index/travelPage")
    public String travelPage(Model model, @ModelAttribute("qo") TravelQueryObject qo){
        qo.setState(2);
        PageInfo pageInfo = travelService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "index/travelPageTpl";
    }
}
